﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace RuTrackerLib
{
    public static class WebFolderManager
    {
        public static string GetParentFolder(string url)
        {
            Uri uri = new Uri(url);
            string result = url;
            if (uri.Segments.Length > 1)
            {
                if(!string.IsNullOrEmpty(uri.Query))
                    result = result.Remove(result.Length - uri.Query.Length, uri.Query.Length);
                result = result.Remove(result.Length - uri.Segments.Last().Length, uri.Segments.Last().Length);
            
            }

            while(result.EndsWith("/"))
                result = result.Remove(result.Length - 1, 1);

            return result;
        }

    }
}
